import { ref } from 'vue'
import { AddChildNetworkTypeForm } from './types'
import { saveType } from '@/api/basic'

export default () => {
  const addChildNetworkTypeLoading = ref(false)

  const addChildNetworkTypeForm = ref<AddChildNetworkTypeForm>({
    id: '',
    name: '',
    status: false,
    childData: [],
    parentId: '',
  })

  const resetAddChildNetworkTypeForm = () => {
    addChildNetworkTypeForm.value = {
      id: '',
      name: '',
      status: false,
      childData: [],
      parentId: '',
    }
  }

  const addChildNetworkType = async () => {
    addChildNetworkTypeLoading.value = true
    const res = await saveType(addChildNetworkTypeForm.value)
    addChildNetworkTypeLoading.value = false
    return res.data as { message: string; code: number; data: object; success: boolean }
  }

  return {
    addChildNetworkTypeForm,
    addChildNetworkTypeLoading,
    addChildNetworkType,
    resetAddChildNetworkTypeForm,
  }
}
